package com.study.daily.algozuo.y2021.m10.day1022;

/**
 * Code01_ReverseList
 *
 * @author Tom on 2021/10/22
 */
public class Code01_ReverseList {
    public static Node deleteGivenValue(Node head, int target) {
        while (head != null && head.value == target) {
            head = head.next;
        }

        Node pre = head;
        Node cur = head.next;
        while (cur != null) {
            if (cur.value == target) {
                pre.next = cur.next;
            } else {
                pre = pre.next;
            }
               cur = cur.next;
        }
        return head;
    }

    public static DoubleNode reverse(DoubleNode head) {
        if (head == null) {
            return null;
        }
        DoubleNode pre = null;

        DoubleNode next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            head.pre = next;
            pre = head;
            head = head.next;
        }
        return pre;
    }

    public static Node reverseNode(Node head) {
        Node pre = null;
        Node next = null;
        while (head != null) {
            next = head.next;
            head.next = pre;
            pre = head;
            head = next;
        }
        return pre;
    }
}

class DoubleNode {
    public DoubleNode pre;
    public DoubleNode next;
    public int value;

    DoubleNode(int value) {
        this.value = value;
    }
}

class Node {
    public Node next;
    public int value;

    public Node(int value) {
        this.value = value;
    }
}
